package com.example.demo01;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

public class Login extends AppCompatActivity {
    EditText passwod;
    Button passwordbutton;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        passwod = findViewById(R.id.password);
        passwordbutton = findViewById(R.id.passwordbutton);
        passwordbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String pwd = passwod.getText().toString();
                OkGo.<String>get("http://121.199.57.242:8080/demo/pwdLogin")
                        .tag(this)
                        .params("pwd",pwd)
                        .execute(new StringCallback() {
                            @Override
                            public void onSuccess(Response<String> response) {
                                if(response.body().equals("1")){
                                    Intent intent = new Intent(Login.this,MainActivity.class);
                                    startActivity(intent);
                                }else{
                                    Toast.makeText(Login.this,"密码错误",Toast.LENGTH_SHORT).show();
                                }
                            }
                        });
            }
        });
    }
}
